#include <iostream.h>//cin cout

#include <iomanip.h>//setw();

#include <fstream.h>//to read from the file input>> input.fail();

//contain class ifstream;

#include <conio.h>//clrscr();

#include <dos.h>//sound(); nosound();delay();

#define Dimen 120 //matrix`s maximum Dimension

#define File_name "matrix.txt" //input file name

int n;

float mat[Dimen][Dimen];//matrix

inline void changecolmn(int,int);//zeroing the upper triangular part of matrix

void normal_read(void);//called if the error when reading(oppening)

 

void main(void)

{

clrscr();

cout<<"Copyright (c) HrayrSoft International 2000 sep 25, All rights reserved ";

cout<<endl<<"Unauthorised use, dublication or distribution is strictly prohibited by federal law";

delay(3000);

clrscr();

int i,j;

cout<<'\r'<<"This program is comput the determinant of sqare matrix N x N (N<120)"<<endl

<<"wich is contained in the file of curent folder called \""<<File_name<<'\"';

ifstream input(File_name);//oppening file

if (!input.fail())//chaking that the file is normaly oppened

{

cout<<endl<<"curent matrix is - "<<endl;

input>>n;//reading matrix`s dimension

for (i=0;i<n;i++) // |

{ for (j=0;j<n;j++) // reading matrix

{ input>>mat[i][j]; // |

cout<<setw(5)<<mat[i][j];//

} //

cout<<endl; //

} //

} //

for (i=0;i<n-1;i++) // THE MAIN PART

for (j=i+1;j<n;j++) // sorting matrix

changecolmn(i,j); // THE MAIN PART !!!!!!!!!!

float det=1.0;

for (i=0;i<n;i++) det*=mat[i][i]; //compute determinant

cout<<" det="<<det;

if (input.fail()) normal_read(); //if file is NOT normaly readed

}

inline void changecolmn(int y,int x)

{

float coefitient=mat[y][x]/mat[y][y];

int i;

for (i=y;i<n;i++) mat[i][x]-=mat[i][y]*coefitient;

}

 

void normal_read(void)

{

sound(440);

cout<<endl<<endl<<"\Error reading(or oppening) \""<<File_name<<"\" file"<<endl

<<"check that you have been set the correct parameters"<<endl

<<"at the first set the N and after that whole matrix e.g."<<endl<<endl

<<"\t\t\tn"

<<endl<<"\t\t\ta(1,1) ... a(1,n)"

<<endl<<"\t\t\t................."

<<endl<<"\t\t\ta(n,1) ... a(n,n)"

<<endl<<" for example -"

<<endl<<"\t2\n\t1 2.03\n\t3 0.01\n";

delay(400);

nosound();

}